package com.yidu.t299.dao.fxj;


import com.yidu.t299.domain.fxj.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface SyllabussMapper {
    //实现查找教室
    @Select("select * from classroom")
    @Results(id = "classroom",value = {
            @Result(id = true,column = "classRoom_id",property = "classRoomId"),
            @Result(column = "classRoom_name",property = "classRoomName")
    })
    List<ClassRoom> classroom();

    //查找班级
    @Select("select class_id , class_name from class")
    @Results(id = "class",value = {
            @Result(id = true,column = "class_id",property = "classId"),
            @Result(column = "class_name",property = "className")
    })
    List<ClassS> classSelect();

    //查找老师
    @Select("select record_id , record_name from record")
    @Results(id = "teacher",value = {
            @Result(id = true,column = "record_id",property = "recordId"),
            @Result(column = "record_name",property = "recordName")
    })
    List<Record> teacher();


    //查找科目
    @Select("select lesson_id , lesson_name from lesson ")
    @Results(id = "lesson",value = {
            @Result(id = true,column = "lesson_id",property = "lessonId"),
            @Result(column = "lesson_name",property = "lessonName")
    })
    List<LessonDomain> lesson();


    //新增
    @Select("insert into syllabus (syllabus_id,syllabus_date,AM_PM,week_name,lesson_id,classroom_id,class_id,record_id) " +
            " values ( #{syllabusId,jdbcType=INTEGER},#{syllabusDate,jdbcType=VARCHAR},#{ampm,jdbcType=VARCHAR}," +
            "#{weekName,jdbcType=VARCHAR},#{lessonId,jdbcType=INTEGER},#{classroomId," +
            "jdbcType=INTEGER},#{classId,jdbcType=INTEGER},#{recordId,jdbcType=INTEGER} )")
    Integer insert(Syllabus syllabus);


    //得到syllabusId列的最大id值
    @Select(" select max(syllabus_id) from syllabus ")
    int syllabusIdMax();

    //查一周中星期n的课
    @Select("select * from (select  syllabus_date ,AM_PM,week_name,lesson_name,classroom_name , class_name,record_name from syllabus " +
            "join class on class.class_id = syllabus.class_id " +
            "join classroom on classroom.classRoom_id = syllabus.classroom_id " +
            "join lesson on lesson.lesson_id = syllabus.lesson_id " +
            "join record on record.record_id = syllabus.record_id ) k " +
            "where syllabus_date > '2023-3-13' and syllabus_date < '2023-3-18' and week_name = #{weekName,jdbcType=VARCHAR} " +
            "  order by AM_PM ")
    @Results(id = "syllabusP",value = {
            @Result(column = "syllabus_date", property = "syllabusDate"),
            @Result(column = "AM_PM",property = "ampm"),
            @Result(column = "week_name",property = "weekName"),
            @Result(column = "lesson_name",property = "lessonName"),
            @Result(column = "classroom_name",property = "classroomName"),
            @Result(column = "class_name",property = "className"),
            @Result(column = "record_name",property = "recordName")
    })
    List<SyllabusP> select(String weekName);

    //查当前星期 星期几有课
    @Select(" select distinct week_name FROM ( select * from (select  syllabus_date ,AM_PM,week_name,lesson_name,classroom_name , class_name,record_name from syllabus " +
            "join class on class.class_id = syllabus.class_id " +
            "join classroom on classroom.classRoom_id = syllabus.classroom_id " +
            "join lesson on lesson.lesson_id = syllabus.lesson_id " +
            "join record on record.record_id = syllabus.record_id ) k " +
            "where syllabus_date > '2023-3-13' and syllabus_date < '2023-3-18' " +
            "  order by syllabus_date ) k")
    String[] selectWeekName();
}
